#include "Sync.h"

uint32_t            gloabal_time=0; //全局时钟（x10ms)

//*******************************************************************************
// 全局时钟,时钟信息保存在noninit寄存器，重启不丢失
//*******************************************************************************
uint32_t GLBO_Timer_INC(uint8_t _10ms)
{
  uint32_t ret;
  gloabal_time += _10ms;
  RTC_WriteBackupRegister(0, gloabal_time>>16);
  RTC_WriteBackupRegister(1, gloabal_time);
  ret = (uint32_t)(gloabal_time%4000);                                                       //40S
  return ret;
}

uint32_t GLBO_Timer_DEC(uint8_t _10ms)
{
  uint32_t ret;
  gloabal_time -= _10ms;
  RTC_WriteBackupRegister(0, gloabal_time>>16);
  RTC_WriteBackupRegister(1, gloabal_time);
  ret = (uint32_t)(gloabal_time%4000);                                                       //40S
  return ret;
}

uint32_t GLBO_Timer_SAVE(uint32_t time)
{
  uint32_t ret;
  gloabal_time = time;
  RTC_WriteBackupRegister(0, time>>16);
  RTC_WriteBackupRegister(1, time);
  ret =  (uint32_t)(gloabal_time%4000);                                                
  return ret;
}

void GLBO_Timer_RELOAD()
{
  uint16_t gt_h,gt_l;
  gt_h = RTC_ReadBackupRegister(0);
  gt_l = RTC_ReadBackupRegister(1);
  gloabal_time = (gt_h<<16)|gt_l;
}